#!/usr/bin/env bash
#filename: remk_dir.sh

#set -x

SCRIPT_NAME=$(basename "$0")
SCRIPT_DIR=$(cd "$(dirname "$0")";pwd)
CUR_DIR=$(pwd)

remake_directory_defaults() {
	[ -d ${CUR_DIR}/dev ] || mkdir -p ${CUR_DIR}/dev
	[ -d ${CUR_DIR}/sys ] || mkdir -p ${CUR_DIR}/sys
	[ -d ${CUR_DIR}/proc ] || mkdir -p ${CUR_DIR}/proc
	[ -d ${CUR_DIR}/overlay ] || mkdir -p ${CUR_DIR}/overlay
	[ -d ${CUR_DIR}/mnt ] || mkdir -p ${CUR_DIR}/mnt
	[ -d ${CUR_DIR}/root ] || mkdir -p ${CUR_DIR}/root
	[ -d ${CUR_DIR}/home ] || mkdir -p ${CUR_DIR}/home

	[ -d ${CUR_DIR}/etc/crontabs ] || mkdir -p ${CUR_DIR}/etc/crontabs
	[ -d ${CUR_DIR}/etc/conntrackd ] || mkdir -p ${CUR_DIR}/etc/conntrackd
	[ -d ${CUR_DIR}/etc/luci-uploads ] || mkdir -p ${CUR_DIR}/etc/luci-uploads
	[ -d ${CUR_DIR}/etc/ssl/certs ] || mkdir -p ${CUR_DIR}/etc/ssl/certs
	[ -d ${CUR_DIR}/etc/ssl/private ] || mkdir -p ${CUR_DIR}/etc/ssl/private

	[ -d ${CUR_DIR}/lib/firmware ] || mkdir -p ${CUR_DIR}/lib/firmware

	[ -d ${CUR_DIR}/usr/lib/lua/posix ] || mkdir -p ${CUR_DIR}/usr/lib/lua/posix
	[ -d ${CUR_DIR}/usr/lib/opkg/lists ] || mkdir -p ${CUR_DIR}/usr/lib/opkg/lists
	[ -d ${CUR_DIR}/usr/local/natshell/nac/local_portal/cgi-bin ] || mkdir -p ${CUR_DIR}/usr/local/natshell/nac/local_portal/cgi-bin

	[ -d ${CUR_DIR}/tmp ] || mkdir -p ${CUR_DIR}/tmp
	[ -d ${CUR_DIR}/tmp ] && chmod 1777 ${CUR_DIR}/tmp
}

echo "remake directory defaults in ${CUR_DIR} ..."
[ -d ${CUR_DIR}/rom ] && remake_directory_defaults
echo "remake directory defaults in ${CUR_DIR} done."

exit 0

